﻿using System;
using System.Collections.Generic;
using System.Text; 
using System.Data;

using MyHotel_DTO;
using MyHotel_Common;
using System.Data.SqlClient;

namespace MyHotel_DAO
{
    public class TaiKhoanDAO : DAO
    {
        protected override Object createObjectFromDatarow(DataRow row)
        {
            TaiKhoan taikhoan = new TaiKhoan();
            taikhoan.MaTaiKhoan = Convert.ToInt32(row["MaTaiKhoan"]);
            taikhoan.TenDangNhap = row["TenDangNhap"].ToString();
            taikhoan.MatKhau = row["MatKhau"].ToString();
            taikhoan.MaChucVu = Convert.ToInt32(row["MaChucVu"]);
            return taikhoan;
        }
        
        public List<TaiKhoan> getList()
        {
            string procName = "SP_GETLIST_TAIKHOAN";
            DataTable dt = DataProvider.executeStoreProcedureQuery(procName);
            return getListFromDataTable<TaiKhoan>(dt);
        }
        public bool themTaiKhoan(TaiKhoan taikhoan)
        {
            string nameProc = "SP_THEM_TAIKHOAN";
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@TENDANGNHAP", taikhoan.TenDangNhap);
            para[1] = new SqlParameter("@MATKHAU", taikhoan.MatKhau);
            para[2] = new SqlParameter("@MACHUCVU", taikhoan.MaChucVu);
            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1);
        } 
    }
}
